<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="en">
<head>
<title>EvaluationException (POI API Documentation)</title>
<link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style">
</head>
<body>
<script type="text/javascript"><!--
    if (location.href.indexOf('is-external=true') == -1) {
        parent.document.title="EvaluationException (POI API Documentation)";
    }
//-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar_top">
<!--   -->
</a><a href="#skip-navbar_top" title="Skip navigation links"></a><a name="navbar_top_firstrow">
<!--   -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="class-use/EvaluationException.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../../org/apache/poi/ss/formula/eval/ErrorEval.html" title="class in org.apache.poi.ss.formula.eval"><span class="strong">PREV CLASS</span></a></li>
<li><a href="../../../../../../org/apache/poi/ss/formula/eval/ExternalNameEval.html" title="class in org.apache.poi.ss.formula.eval"><span class="strong">NEXT CLASS</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../../index.html?org/apache/poi/ss/formula/eval/EvaluationException.html" target="_top">FRAMES</a></li>
<li><a href="EvaluationException.html" target="_top">NO FRAMES</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../../../allclasses-noframe.html">All Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
  allClassesLink = document.getElementById("allclasses_navbar_top");
  if(window==top) {
    allClassesLink.style.display = "block";
  }
  else {
    allClassesLink.style.display = "none";
  }
  //-->
</script>
</div>
<div>
<ul class="subNavList">
<li>SUMMARY:&nbsp;</li>
<li>NESTED&nbsp;|&nbsp;</li>
<li>FIELD&nbsp;|&nbsp;</li>
<li><a href="#constructor_summary">CONSTR</a>&nbsp;|&nbsp;</li>
<li><a href="#method_summary">METHOD</a></li>
</ul>
<ul class="subNavList">
<li>DETAIL:&nbsp;</li>
<li>FIELD&nbsp;|&nbsp;</li>
<li><a href="#constructor_detail">CONSTR</a>&nbsp;|&nbsp;</li>
<li><a href="#method_detail">METHOD</a></li>
</ul>
</div>
<a name="skip-navbar_top">
<!--   -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<p class="subTitle">org.apache.poi.ss.formula.eval</p>
<h2 title="Class EvaluationException" class="title">Class EvaluationException</h2>
</div>
<div class="contentContainer">
<ul class="inheritance">
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li>java.lang.Throwable</li>
<li>
<ul class="inheritance">
<li>java.lang.Exception</li>
<li>
<ul class="inheritance">
<li>org.apache.poi.ss.formula.eval.EvaluationException</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<div class="description">
<ul class="blockList">
<li class="blockList">
<dl>
<dt>All Implemented Interfaces:</dt>
<dd>java.io.Serializable</dd>
</dl>
<hr>
<br>
<pre>public final class <strong>EvaluationException</strong>
extends java.lang.Exception</pre>
<div class="block">This class is used to simplify error handling logic <i>within</i> operator and function
 implementations.   Note - <tt>OperationEval.evaluate()</tt> and <tt>Function.evaluate()</tt>
 method signatures do not throw this exception so it cannot propagate outside.<p/>
 
 Here is an example coded without <tt>EvaluationException</tt>, to show how it can help:
 <pre>
 public Eval evaluate(Eval[] args, int srcRow, short srcCol) {
        // ...
        Eval arg0 = args[0];
        if(arg0 instanceof ErrorEval) {
                return arg0;
        }
        if(!(arg0 instanceof AreaEval)) {
                return ErrorEval.VALUE_INVALID;
        }
        double temp = 0;
        AreaEval area = (AreaEval)arg0;
        ValueEval[] values = area.getValues();
        for (int i = 0; i < values.length; i++) {
                ValueEval ve = values[i];
                if(ve instanceof ErrorEval) {
                        return ve;
                }
                if(!(ve instanceof NumericValueEval)) {
                        return ErrorEval.VALUE_INVALID;
                }
                temp += ((NumericValueEval)ve).getNumberValue();
        }
        // ...
 }       
 </pre>
 In this example, if any error is encountered while processing the arguments, an error is 
 returned immediately. This code is difficult to refactor due to all the points where errors
 are returned.<br/>
 Using <tt>EvaluationException</tt> allows the error returning code to be consolidated to one
 place.<p/>
 <pre>
 public Eval evaluate(Eval[] args, int srcRow, short srcCol) {
        try {
                // ...
                AreaEval area = getAreaArg(args[0]);
                double temp = sumValues(area.getValues());
                // ...
        } catch (EvaluationException e) {
                return e.getErrorEval();
        }
}

private static AreaEval getAreaArg(Eval arg0) throws EvaluationException {
        if (arg0 instanceof ErrorEval) {
                throw new EvaluationException((ErrorEval) arg0);
        }
        if (arg0 instanceof AreaEval) {
                return (AreaEval) arg0;
        }
        throw EvaluationException.invalidValue();
}

private double sumValues(ValueEval[] values) throws EvaluationException {
        double temp = 0;
        for (int i = 0; i < values.length; i++) {
                ValueEval ve = values[i];
                if (ve instanceof ErrorEval) {
                        throw new EvaluationException((ErrorEval) ve);
                }
                if (!(ve instanceof NumericValueEval)) {
                        throw EvaluationException.invalidValue();
                }
                temp += ((NumericValueEval) ve).getNumberValue();
        }
        return temp;
}
 </pre>   
 It is not mandatory to use EvaluationException, doing so might give the following advantages:<br/>
  - Methods can more easily be extracted, allowing for re-use.<br/>
  - Type management (typecasting etc) is simpler because error conditions have been separated from
 intermediate calculation values.<br/>
  - Fewer local variables are required. Local variables can have stronger types.<br/>
  - It is easier to mimic common Excel error handling behaviour (exit upon encountering first 
  error), because exceptions conveniently propagate up the call stack regardless of execution 
  points or the number of levels of nested calls.<p/>
  
 <b>Note</b> - Only standard evaluation errors are represented by <tt>EvaluationException</tt> (
 i.e. conditions expected to be encountered when evaluating arbitrary Excel formulas). Conditions
 that could never occur in an Excel spreadsheet should result in runtime exceptions. Care should
 be taken to not translate any POI internal error into an Excel evaluation error code.</div>
<dl><dt><span class="strong">Author:</span></dt>
  <dd>Josh Micich</dd>
<dt><span class="strong">See Also:</span></dt><dd><a href="../../../../../../serialized-form.html#org.apache.poi.ss.formula.eval.EvaluationException">Serialized Form</a></dd></dl>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor_summary">
<!--   -->
</a>
<h3>Constructor Summary</h3>
<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Constructor Summary table, listing constructors, and an explanation">
<caption><span>Constructors</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colOne" scope="col">Constructor and Description</th>
</tr>
<tr class="altColor">
<td class="colOne"><code><strong><a href="../../../../../../org/apache/poi/ss/formula/eval/EvaluationException.html#EvaluationException(org.apache.poi.ss.formula.eval.ErrorEval)">EvaluationException</a></strong>(<a href="../../../../../../org/apache/poi/ss/formula/eval/ErrorEval.html" title="class in org.apache.poi.ss.formula.eval">ErrorEval</a>&nbsp;errorEval)</code>&nbsp;</td>
</tr>
</table>
</li>
</ul>
<!-- ========== METHOD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="method_summary">
<!--   -->
</a>
<h3>Method Summary</h3>
<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
<caption><span>Methods</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Method and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code><a href="../../../../../../org/apache/poi/ss/formula/eval/ErrorEval.html" title="class in org.apache.poi.ss.formula.eval">ErrorEval</a></code></td>
<td class="colLast"><code><strong><a href="../../../../../../org/apache/poi/ss/formula/eval/EvaluationException.html#getErrorEval()">getErrorEval</a></strong>()</code>&nbsp;</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static <a href="../../../../../../org/apache/poi/ss/formula/eval/EvaluationException.html" title="class in org.apache.poi.ss.formula.eval">EvaluationException</a></code></td>
<td class="colLast"><code><strong><a href="../../../../../../org/apache/poi/ss/formula/eval/EvaluationException.html#invalidRef()">invalidRef</a></strong>()</code>
<div class="block"><b>#REF!</b> - Illegal or deleted cell reference</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static <a href="../../../../../../org/apache/poi/ss/formula/eval/EvaluationException.html" title="class in org.apache.poi.ss.formula.eval">EvaluationException</a></code></td>
<td class="colLast"><code><strong><a href="../../../../../../org/apache/poi/ss/formula/eval/EvaluationException.html#invalidValue()">invalidValue</a></strong>()</code>
<div class="block"><b>#VALUE!</b> - Wrong type of operand</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static <a href="../../../../../../org/apache/poi/ss/formula/eval/EvaluationException.html" title="class in org.apache.poi.ss.formula.eval">EvaluationException</a></code></td>
<td class="colLast"><code><strong><a href="../../../../../../org/apache/poi/ss/formula/eval/EvaluationException.html#numberError()">numberError</a></strong>()</code>
<div class="block"><b>#NUM!</b> - Value range overflow</div>
</td>
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods_inherited_from_class_java.lang.Throwable">
<!--   -->
</a>
<h3>Methods inherited from class&nbsp;java.lang.Throwable</h3>
<code>fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString</code></li>
</ul>
<ul class="blockList">
<li class="blockList"><a name="methods_inherited_from_class_java.lang.Object">
<!--   -->
</a>
<h3>Methods inherited from class&nbsp;java.lang.Object</h3>
<code>clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait</code></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor_detail">
<!--   -->
</a>
<h3>Constructor Detail</h3>
<a name="EvaluationException(org.apache.poi.ss.formula.eval.ErrorEval)">
<!--   -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>EvaluationException</h4>
<pre>public&nbsp;EvaluationException(<a href="../../../../../../org/apache/poi/ss/formula/eval/ErrorEval.html" title="class in org.apache.poi.ss.formula.eval">ErrorEval</a>&nbsp;errorEval)</pre>
</li>
</ul>
</li>
</ul>
<!-- ============ METHOD DETAIL ========== -->
<ul class="blockList">
<li class="blockList"><a name="method_detail">
<!--   -->
</a>
<h3>Method Detail</h3>
<a name="invalidValue()">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>invalidValue</h4>
<pre>public static&nbsp;<a href="../../../../../../org/apache/poi/ss/formula/eval/EvaluationException.html" title="class in org.apache.poi.ss.formula.eval">EvaluationException</a>&nbsp;invalidValue()</pre>
<div class="block"><b>#VALUE!</b> - Wrong type of operand</div>
</li>
</ul>
<a name="invalidRef()">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>invalidRef</h4>
<pre>public static&nbsp;<a href="../../../../../../org/apache/poi/ss/formula/eval/EvaluationException.html" title="class in org.apache.poi.ss.formula.eval">EvaluationException</a>&nbsp;invalidRef()</pre>
<div class="block"><b>#REF!</b> - Illegal or deleted cell reference</div>
</li>
</ul>
<a name="numberError()">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>numberError</h4>
<pre>public static&nbsp;<a href="../../../../../../org/apache/poi/ss/formula/eval/EvaluationException.html" title="class in org.apache.poi.ss.formula.eval">EvaluationException</a>&nbsp;numberError()</pre>
<div class="block"><b>#NUM!</b> - Value range overflow</div>
</li>
</ul>
<a name="getErrorEval()">
<!--   -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>getErrorEval</h4>
<pre>public&nbsp;<a href="../../../../../../org/apache/poi/ss/formula/eval/ErrorEval.html" title="class in org.apache.poi.ss.formula.eval">ErrorEval</a>&nbsp;getErrorEval()</pre>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar_bottom">
<!--   -->
</a><a href="#skip-navbar_bottom" title="Skip navigation links"></a><a name="navbar_bottom_firstrow">
<!--   -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="class-use/EvaluationException.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../../org/apache/poi/ss/formula/eval/ErrorEval.html" title="class in org.apache.poi.ss.formula.eval"><span class="strong">PREV CLASS</span></a></li>
<li><a href="../../../../../../org/apache/poi/ss/formula/eval/ExternalNameEval.html" title="class in org.apache.poi.ss.formula.eval"><span class="strong">NEXT CLASS</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../../index.html?org/apache/poi/ss/formula/eval/EvaluationException.html" target="_top">FRAMES</a></li>
<li><a href="EvaluationException.html" target="_top">NO FRAMES</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../../../allclasses-noframe.html">All Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
  allClassesLink = document.getElementById("allclasses_navbar_bottom");
  if(window==top) {
    allClassesLink.style.display = "block";
  }
  else {
    allClassesLink.style.display = "none";
  }
  //-->
</script>
</div>
<div>
<ul class="subNavList">
<li>SUMMARY:&nbsp;</li>
<li>NESTED&nbsp;|&nbsp;</li>
<li>FIELD&nbsp;|&nbsp;</li>
<li><a href="#constructor_summary">CONSTR</a>&nbsp;|&nbsp;</li>
<li><a href="#method_summary">METHOD</a></li>
</ul>
<ul class="subNavList">
<li>DETAIL:&nbsp;</li>
<li>FIELD&nbsp;|&nbsp;</li>
<li><a href="#constructor_detail">CONSTR</a>&nbsp;|&nbsp;</li>
<li><a href="#method_detail">METHOD</a></li>
</ul>
</div>
<a name="skip-navbar_bottom">
<!--   -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<p class="legalCopy"><small>
                <i>Copyright 2014 The Apache Software Foundation or
        its licensors, as applicable.</i>
            </small></p>
</body>
</html>
